--火中取利
local huozhongquli = fk.CreateSkill {
    name = "mcdh_huozhongquli",
}

local U = require "packages/utility/utility"
local lib = require "packages/mcdh/lib"

huozhongquli:addEffect('active',{
    can_use = function(self, player)
        return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
    end,
    on_use = function(self, room, effect)
        local player = effect.from
        local  cards = room:drawCards(player,1+#player:getPile("mcdh__xin"),self.name,"bottom")
        player:showCards(cards)
        local colors = {}
        for _, id in ipairs(cards) do
            table.insertIfNeed(colors, Fk:getCardById(id).color)
        end
        if #colors ~= 1 and not table.contains(colors, Card.NoColor)then
            room:askForDiscard(player, 1, 1, true, self.name, false, ".", "#mcdh_huozhongquli-discard::")
            lib.Damage({ from = nil, to = player, damage = 1, skillName = self.name })
        elseif #colors == 1 and colors[1] == Card.Red then
            player:addToPile("mcdh__xin", room:getNCards(1), true, self.name)
        elseif #colors == 1 and colors[1]== Card.Black and #player:getPile("mcdh__xin") >0 then
            local remove = room:askForCard(player, 1, 1, false, self.name, false, ".|.|.|mcdh__xin", "#mcdh_huozhongquli-remove::","mcdh__xin")
            room:moveCards({
                ids = remove,
                from = player,
                toArea = Card.DiscardPile,
                moveReason = fk.ReasonJustMove,
                skillName = self.name,
            })
        end
    end,
})

Fk:loadTranslationTable{
    ["mcdh_huozhongquli"] = "火中取利",
    [":mcdh_huozhongquli"] ="出牌阶段限一次，你可以从牌堆底摸X+1张牌并展示，若这些牌的颜色：为红，你将牌堆顶的一张牌置于你的武将牌旁，称为「薪」；为黑，你移去一张「薪」；不同，你弃置一张牌并受到1点无来源伤害（X为「薪」数）。",
    ["#mcdh_huozhongquli-discard"] = "火中取利:请弃置一张牌",
    ["#mcdh_huozhongquli-remove"] ="火中取利:请移去一张牌「薪」",
    ["mcdh__xin"] = "薪",

}

return huozhongquli